var basePath;

var bookCoverPath;


$(function() {
	var curPath = window.document.location.href;
    //获取主机地址之后的目录，如： test/test.jsp
    var pathName = window.document.location.pathname;
    var pos = curPath.indexOf(pathName);
    //获取主机地址，如： http://localhost:8088
    var basePath_ = curPath.substring(0, pos);
  //获取带"/"的项目名，如：/test
    var projectName = pathName.substring(0, pathName.substr(1).indexOf('/') + 1);
    basePath = basePath_+projectName;
    
    bookCoverPath = basePath + '/images/bookcover/';
    console.info(bookCoverPath);
})



/**
 * 切换界面
 * 
 * @param method
 * @param url
 * @param params
 * @param div
 */
function changeCenter(title, method, url, params) {
	if(existsTab(title)) {
		$("#centerTab").tabs('select', title);
	} else {
		var args = {time : new Date()};
		if(null != params && params != 'undefine')
		args = iterator(this.args, params);
		$.ajax({
	        type: method,
	        url: url,
	        data: args,
	        success: function(data){
	        	$("#centerTab").tabs('add',{
	    			title:title,
	    			content:data,
	    			closable:true
	    		});
	        }
	    });
	}
}

/**
 * 查看是否已经存在这个选项卡
 * @param title
 * @returns {Boolean}
 */
function existsTab(title) {
	if($("#centerTab").tabs('exists', title)) {
		return true;
	}
	return false;
}



//工具方法：对象追加对象
function iterator(base, data) {
	if(null != data && data != '') {
		for (var Key in data){
			base[Key] = data[Key];
		}
	}
	return base;
}